package com.ice.body.log.controller;
import com.ice.body.log.model.LogAir;
import com.ice.body.log.service.LogAirService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import com.ice.base.controller.BaseController;
import org.slf4j.Logger;
import com.github.pagehelper.PageHelper;
import org.springframework.util.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import com.ice.base.result.ResponseResult;
import com.ice.base.result.AjaxResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2022-11-11
 * Time: 03:33
 */
@RestController
@ApiIgnore(value = "空气质量记录")
public class LogAirController extends BaseController{
    private Logger logger = LoggerFactory.getLogger(getClass());
    //---------------------------空气质量记录-----------------------start
    @Resource
    private LogAirService logAirService;
    
    @ApiOperation(value = "空气质量记录-新增")
    @PostMapping("/api/LogAir/insert")
    public AjaxResult<LogAir> insert_LogAir(LogAir model) {
        AjaxResult r = AjaxResult.success();
        try{
            Integer count  = logAirService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = AjaxResult.error(); 
        }
        return r;
    }

    @ApiOperation(value = "空气质量记录-删除")
    @PostMapping("/api/LogAir/deleteById")
    public AjaxResult<LogAir>  deleteById_LogAir(@RequestParam("id") String id) {
        AjaxResult r = AjaxResult.success();
        try{
            Integer count =logAirService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = AjaxResult.error();  
        }
        return r;
    }

    @ApiOperation(value = "空气质量记录-更新")
    @PostMapping("/api/LogAir/updateById")
    public AjaxResult<LogAir> update_LogAir(LogAir model) {
        try{
            Integer count =logAirService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();      
        }
        return AjaxResult.success();
    }

    @ApiOperation(value = "空气质量记录-查询一个")
    @PostMapping("/api/LogAir/selectById")
    public AjaxResult<LogAir> selectById_LogAir(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           LogAir model = logAirService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "空气质量记录-查询多个")
    @PostMapping("/api/LogAir/selectAll")
    public AjaxResult<LogAir> selectList_LogAir(LogAir model) {
        AjaxResult r = AjaxResult.success();
        try{
           List<LogAir> list = logAirService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "空气质量记录-查询分页")
    @PostMapping("/api/LogAir/selectListByPageHelper")
    public AjaxResult<LogAir> selectListByPageHelper_LogAir(@RequestParam(name = "pageSize") Integer pageSize,
                                                         @RequestParam(name = "pageNum") Integer pageNum,
                                                         LogAir model){ 
        AjaxResult r = AjaxResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
             list = logAirService.selectListByModel(model);
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------空气质量记录-----------------------end
}
